#region File Description
//-----------------------------------------------------------------------------
// Game.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
using ForgottenTalez.GameStateManager.ScreenMan;
using ForgottenTalez.GameStateManager.Screens.MenuScreens;
using ForgottenTalez.GameStateManager.Screens.TransitionScreens;
using ForgottenTalez.InputManager;
using ForgottenTalez.Renderers;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;


namespace ForgottenTalez
{
    /// <summary>
    /// Sample showing how to manage different game states, with transitions
    /// between menu screens, a loading screen, the game itself, and a pause
    /// menu. This main game class is extremely simple: all the interesting
    /// stuff happens in the ScreenManager component.
    /// </summary>
    public class ForgottenTalezGame : Microsoft.Xna.Framework.Game
    {
        #region Fields

        GraphicsDeviceManager graphics;
        ScreenManager screenManager;


        // By preloading any assets used by UI rendering, we avoid framerate glitches
        // when they suddenly need to be loaded in the middle of a menu transition.
        static readonly string[] preloadAssets =
        {
            "gradient",
        };


        #endregion

        #region Initialization


        /// <summary>
        /// The main game constructor.
        /// </summary>
        public ForgottenTalezGame()
        {
            Content.RootDirectory = "Content";

            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 420;
            graphics.PreferredBackBufferHeight = 270;

            // Create the screen manager component.
            screenManager = new ScreenManager(this);

            Components.Add(screenManager);
            Components.Add(Input.InitializeAndGetInstance(this));
        }

        /// <summary>
        /// Loads graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            foreach (string asset in preloadAssets)
            {
                Content.Load<object>(asset);
            }

            LoadingScreen.Load(screenManager, true, new WelcomeScreenRenderer(screenManager)
                , new MainMenuScreen(true,
                    new BackgroundRenderer(screenManager, Content.Load<Texture2D>(@"GSMAssets\backgrounds\TestBackground")))).WaitUntilTrueEvent += ContinueFromWelcomeScreen;

           // Activate the first screen
        }
        /// <summary>
        /// This method will keep the Welcome screen active until Enter is pressed
        /// </summary>
        /// <returns></returns>
        public bool ContinueFromWelcomeScreen()
        {
            if (Input.wasKeyPressed(Keys.Enter))
                return true;
            return false;
        }

        #endregion

        #region Draw

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.Black);
            screenManager.SpriteBatch.Begin();
            // The real drawing happens inside the screen manager component.
            base.Draw(gameTime);
            screenManager.SpriteBatch.End();
        }

        #endregion
    }

#region Entry Point
    #if WINDOWS || XBOX
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            using (ForgottenTalezGame game = new ForgottenTalezGame())
            {
                game.Run();
            }
        }
    }
    #endif
#endregion
}
